package com.woniuxy.verify.controller;

import com.woniuxy.verify.bean.ResultMsg;
import com.woniuxy.verify.bean.StudentBean;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author linke
 * @version 1.0
 * @className: StudentController
 * @description: 学生控制器
 * @date 2021/11/14 15:58
 */
@RestController //等同于   @Controller + @RequestBody
@RequestMapping("stus")
public class StudentController {



    /**
     * 修改学生
     * @param studentBean
     * @return
     * @RequestBody 作用：将消息体中的 JSON对象，反序列化为Java对象
     */
    @RequestMapping(value="/update",produces = {"application/json;charset=utf-8"})
    public ResultMsg updateStudentBean(@RequestBody StudentBean studentBean){
        ResultMsg resultMsg = new ResultMsg("200","保存成功");

        System.out.println(studentBean);//StudentBean(id=null, stuName=一护, stuNo=4578, age=50)

        return resultMsg;
    }

    /**
     * 新增学生
     * 但是不跳转页面
     * @param studentBean
     * @return
     *
     *  @ResponseBody 作用：将Java对象 序列化成JSON对象
     *  并通过响应体完成数据的传输
     *
     *  produces 告诉前端返回的是一个json数据
     */
    @RequestMapping(value="/add",produces = {"application/json;charset=utf-8"})
    @ResponseBody
    public ResultMsg saveStudentBean(StudentBean studentBean){
        ResultMsg resultMsg = new ResultMsg("200","保存成功");

        System.out.println(studentBean);//StudentBean(id=null, stuName=一护, stuNo=4578, age=50)

        return resultMsg;
    }
}
